var vue = new Vue({
    el: '#main',
    data: {
        ticketId: Util.getParam("ticketId"),
        parentMenuCode: Util.getParam("parentMenuCode"),
        prodId: Util.getParam("prodId"),
        screenWidth: document.body.clientWidth,
        screenHeight: document.body.clientHeight,
        isCollapse: false,
        menus: [],
        curBreadcrumbs: [],
        mainPath: '',
        loginUser: {},
    },
    mounted: function () {
        var that = this;
        window.onresize = function () {
            return (function () {
                window.screenWidth = document.body.clientWidth;
                window.screenHeight = document.body.clientHeight;
                that.screenWidth = window.screenWidth;
                that.screenHeight = window.screenHeight;
            })()
        }
    },
    watch: {
        screenWidth: function (val) {
            this.screenWidth = val
            if (val < 750) {
                this.isCollapse = true;
            } else {
                this.isCollapse = false;
            }
        }
    },
    computed: {
        sideWidth: function () {
            return this.isCollapse ? '65px' : '200px';
        },
        menuDivHeight: function () {
            return (this.screenHeight - 60) + 'px';
        },
        mainDivHeight: function () {
            return this.screenHeight + 'px';
        },
        mainHeight: function () {
            return (this.screenHeight - 105) + 'px';
        },
        mainWidth: function () {
            return this.screenWidth - (this.isCollapse ? 85 : 220) + 'px';
        },
        logImg: function () {
            return this.isCollapse ? "../../img/logo-single.png" : "../../img/logo.png";
        }
    },
    created: function () {
        if (Util.getParam("authFlag")) {
            Util.storage.set(Util.USER_INFO_KEY, {ticketId: this.ticketId});
        }
        this.loadMenu();
    },
    methods: {
        checkPath: function (item) {
            let meunPath = item.path.toUpperCase();
            return meunPath.search("HTTP://") == -1 || meunPath.search("HTTPS://") == -1 || meunPath.search(GLOBAL_CONFIG.webSiteRoot) == -1;
        },
        menuClick: function (m1, m2, m3) {
            let menu = m3;
            if (m2 && m2.path) {
                menu = m2;
            } else if (m1 && m1.path) {
                menu = m1;
            }
            this.mainPath = (this.checkPath(menu) ? GLOBAL_CONFIG.webSiteRoot + menu.path : menu.path) + this.getMenuParams(menu);
            this.curBreadcrumbs = [];
            this.curBreadcrumbs.push(m1.name);
            if (m2 && m2.name) this.curBreadcrumbs.push(m2.name);
            if (m3 && m3.name) this.curBreadcrumbs.push(m3.name);
        },
        getMenuParams: function (menu) {
            return ((menu.path.indexOf('?') == -1) ? "?" : "&") + "ticketId=" + this.ticketId + "&menuCode=" + menu.menuCode
        },
        loadMenu: function () {
            var self = this;
            Util.post('/system/menu/listMenuByUser', {parentMenuCode: this.parentMenuCode, orgId: self.loginUser.rootOrgId}, function (result) {
                // Util.post('/system/productMenu/listMenuByLoginUser', {parentMenuCode: this.parentMenuCode}, function (result) {
                if (result.success) {
                    self.menus = result.data || [];
                    self.loginUser = result.extend.loginUser;
                    self.ticketId = self.loginUser.ticketId || self.ticketId;
                    Util.storage.set(Util.USER_INFO_KEY, self.loginUser);
                } else {
                    self.$message.error(result.sysMsg || result.msg);
                }
            })
        },
        logout: function () {
            Util.post('/system/login/logout', null, function (result) {
                if (result.success) {
                    Util.storage.set(Util.USER_INFO_KEY, {});
                    top.location = GLOBAL_CONFIG.webSiteRoot + result.obj;
                }
            });
        }
    }
});
